package com.yunzan.sync_netty.command;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 西绑手环指令
 */
public class BraceletsCommand {
    public final static String product = "IC";
    private static SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss,yyyy-MM-dd");
    public interface COMMAND {
        /**
         * 校准时间
         */
        String CALIBRATION_TIME = "[XX*DEVICEID*LEN*LGZONEDDDD]";
        /**
         * 预警电话设置
         */
        String SOS_OPERATION = "[XX*DEVICEID*LEN*SOSDDDD]";
        /**
         * 推送信息频率
         */
        String MSG_SEND_RATE = "[XX*DEVICEID*LEN*LGZONEDDDD]";
        /**
         * 推送学生信息
         */
        String MSG_SEND_STUDENT= "[XX*DEVICEID*LEN*STUDENTDDDD]";
        /**
         * 推送心率预警值
         */
        String OSO_HEART_DATA= "[XX*DEVICEID*LEN*HRALDDDD]";
        /**
         * 推送血痒的预警值
         */
        String OSO_OXAL_DATA= "[XX*DEVICEID*LEN*OXALDDDD]";
        /**
         * 推送提问预警值
         */
        String OSO_TMAL_DATA= "[XX*DEVICEID*LEN*TMALDDDD]";

    }

    public static String getInstance(String cmd,String  deviceId,String data){
        String command=cmd.replace("DEVICEID",deviceId);
        command=command.replace("XX",product); // 更换产品信息
        if(cmd.equals(COMMAND.CALIBRATION_TIME)){
            data=",+8,"+sdf.format(new Date());
            command=command.replace("DDDD",data);
        }
        String key=cmd.split("\\*")[3].replace("DDDD]","");
        String len=String.format("%04X",(key+data).length());
        command=command.replace("LEN",len);
        if(null!=data){
            command=command.replace("DDDD",data);
        }else{
            command=command.replace("DDDD","");
        }
        return  command;
    }

    public static void main(String[] args) {
       System.out.println(getInstance(COMMAND.SOS_OPERATION,"870314001007394",",13072192261,13072192261"));
      System.out.println(new Date(1634205252467L));
    }

}
